package cn.school.Util;

import java.io.IOException;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class SessionUtil {

	private static SqlSessionFactory sessionFactory;

	static {
		try {
			sessionFactory = new SqlSessionFactoryBuilder().build(Resources
					.getResourceAsStream("mybatisConfig.xml"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static SqlSession getSession() {

		return sessionFactory.openSession(true);
	}

	public static void closeSession(SqlSession s) {
		if (s != null) {
			s.close();
		}
	}

	private SessionUtil() {

	}
}
